#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/4/9  20:43
# @Author: 余浪人
# @email: yulangren520@gmail.com

from apps import create_app
from apps.lib.public import initialize, batch_add
from apps.models.admin_model import Authority_Model, Admin_Model, db
from apps.models.collector_model import Collect_Proxy_Model
from apps.models.system_model import System_Model, Share_Modle, Discuss_Model, API_Modle, Ad_Model, Accredit_Model
from apps.models.other_model import AdCooperation_Model, Infringement_Model, Contribute_Model, Feedback_Model

cms_app = create_app('apps.setting.ProductionConfig')
ad_3 = '''
<table class="table_ad">
	<tbody>
		<tr>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#000069;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#CC33FF;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#006600;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#0000FF;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href=""><span style="font-size:12px;color:#0000CC;">文字广告位</span></a> 
			</td>
		</tr>
		<tr>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FD7E00;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#000000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#006600;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
		</tr>
		<tr>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#0000FF;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#000000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#6633CC;">文字广告位</span></a> 
			</td>
		</tr>
		<tr>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#0000FF;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#006600;">文字广告位 </span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#000000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#0003A2;">文字广告位</span></a> 
			</td>
		</tr>
		<tr>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#0000FF;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#D200D2;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
			<td>
				<a rel="external nofollow" href="" target="_blank"><span style="font-size:12px;color:#FF0000;">文字广告位</span></a> 
			</td>
		</tr>
	</tbody>
</table>
'''
if __name__ == '__main__':
    import datetime

    with cms_app.app_context():
        db.create_all()
        if not len(System_Model.query.filter().all()):
            initialize(System_Model, db)  # 初始化系统设置
            initialize(Share_Modle, db)  # 初始化分享功能
            initialize(Discuss_Model, db)  # 初始化评论功能
            initialize(API_Modle, db)  # 初始化API功能
            initialize(Collect_Proxy_Model, db)  # 初始化IP代理功能
            initialize(AdCooperation_Model, db)  # 初始化广告合作
            initialize(Contribute_Model, db)  # 初始化说明
            initialize(Feedback_Model, db)  # 初始化留言反馈
            initialize(Infringement_Model, db)  # 初始化侵权反馈
            initialize(Accredit_Model, db)  # 初始化授权
            data = [
                {"authority_name": "超级管理员"}, {"authority_name": "会员管理"}, {"authority_name": "档案管理"},
                {"authority_name": "采集管理"}, {"authority_name": "系统管理"}  # 此处切勿修改
            ]
            batch_add(Authority_Model, db, data)  # 初始化管理权限
            data = [{'username': 'root', 'password': 'root', "authority": 1, 'remark': '超级管理员'}, ]
            batch_add(Admin_Model, db, data)  # 初始化默认管理员   建议: 成功登录本系统后,请球盖默认密码
            data = [
                {"ad_name": "全站_导航上侧", "ad_code": "广告位内容1", "ad_description": "系统预设广告",
                 "ad_end_date": datetime.datetime.strptime("2099-12-30", "%Y-%m-%d")},
                {"ad_name": "首页_导航下侧1", "ad_code": "广告位内容2", "ad_description": "系统预设广告",
                 "ad_end_date": datetime.datetime.strptime("2099-12-30", "%Y-%m-%d")},
                {"ad_name": "首页_导航下侧2", "ad_code": ad_3, "ad_description": "系统预设广告",
                 "ad_end_date": datetime.datetime.strptime("2099-12-30", "%Y-%m-%d")},
                {"ad_name": "全站_轮播图下侧", "ad_code": "广告位内容4", "ad_description": "系统预设广告",
                 "ad_end_date": datetime.datetime.strptime("2099-12-30", "%Y-%m-%d")},
                {"ad_name": "详情页_前后页下方", "ad_code": "广告位内容5", "ad_description": "系统预设广告",
                 "ad_end_date": datetime.datetime.strptime("2099-12-30", "%Y-%m-%d")}
            ]
            batch_add(Ad_Model, db, data)  # 初始化广告
    cms_app.run(host="0.0.0.0", port=cms_app.config.get('PORT'),threaded=True)
